package com.xy.exam.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xy.exam.pojo.dto.FeedbackAddNewDTO;
import com.xy.exam.pojo.dto.FeedbackUpdateDTO;
import com.xy.exam.service.IFeedBackService;
import com.xy.exam.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;


@Slf4j
@RequestMapping("/feedback")
@RestController
@Api(tags="06.反馈信息管理")//添加模块名称
public class FeedbackController {
    @Autowired
    IFeedBackService feedbackService;
    @PostMapping("/add-new")
    @ApiOperation(value = "添加反馈信息")//添加名称
    @ApiOperationSupport(order = 100)//排序
    public JsonResult addNew(FeedbackAddNewDTO feedbackAddNewDTO) {
        feedbackService.addNew(feedbackAddNewDTO);
        return new JsonResult().ok();
    }


    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除反馈信息,根据id")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "反馈信息ID", required = true, dataType = "long")
    })
    public JsonResult delete(@Range(min = 1, message = "删除反馈信息失败，ID值无效！")
                             @PathVariable Long id) {
        feedbackService.delete(id);
        return JsonResult.ok();
    }


    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改反馈信息")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "反馈信息ID", required = true, dataType = "long")
    })
    public JsonResult updateFeedbackById(@Range(min = 1, message = "修改反馈信息失败，ID值无效！")
                                     @PathVariable Long id, @Valid FeedbackUpdateDTO feedbackUpdateDTO) {
        feedbackService.updateFeedbackById(id,feedbackUpdateDTO);
        return JsonResult.ok();
    }


    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("查询相册详情,根据id")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "反馈信息ID", required = true, dataType = "long")
    })
    public JsonResult getStandardById(@Range(min = 1, message = "获取反馈信息失败，ID值无效！")
                                      @PathVariable Long id) {

        return JsonResult.ok();
    }


    @GetMapping("/list")
    @ApiOperation("查询反馈信息列表")
    @ApiOperationSupport(order = 420)
    public JsonResult list() {
        return JsonResult.ok(feedbackService.list());
    }
}
